package com.ljw.vendingmachine.base;


import android.app.Activity;
import android.app.ProgressDialog;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.annotation.Nullable;
import android.view.View;



import butterknife.ButterKnife;
import butterknife.Unbinder;

public abstract class BaseActivity extends Activity {

    private Unbinder unbinder;
    public ProgressDialog dialog;


    /**
     * SetContentView之前调用
     */
     public void beforeSetContentView(){
         hideNavigationBar();
     }
    public void afterSetContentView(){

    }
     public abstract int  setContentView();

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        beforeSetContentView();
        super.setContentView(setContentView());
        afterSetContentView();
       // EventBus.getDefault().register(this);
        unbinder = ButterKnife.bind(this);
        dialog = new ProgressDialog(this);
        dialog.setCancelable(true);
        dialog.setTitle("提示");
        dialog.setMessage("网络连接中...");
        initView();
        initData();

    }



    /**
     * 初始化界面空间
     */
    public abstract void initView();
    /**
     * 初始化数据
     */
    public  abstract void initData();



    @Override
    public void onDestroy() {
        super.onDestroy();
      //  EventBus.getDefault().unregister(this);
        if (unbinder!=null)unbinder.unbind();
    }

    public void hideNavigationBar() {
        int uiFlags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION // hide nav bar
                | View.SYSTEM_UI_FLAG_FULLSCREEN; // hide status bar

        if (android.os.Build.VERSION.SDK_INT >= 19) {
            uiFlags |= View.SYSTEM_UI_FLAG_IMMERSIVE;//0x00001000; // SYSTEM_UI_FLAG_IMMERSIVE_STICKY: hide
        } else {
            uiFlags |= View.SYSTEM_UI_FLAG_LOW_PROFILE;
        }

        try {
            getWindow().getDecorView().setSystemUiVisibility(uiFlags);
        } catch (Exception e) {
            // TODO: handle exception
        }

    }
}
